package com.mt.course.service.model;

import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.github.pagehelper.PageHelper;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.course.entity.ZhiboCourseEntity;
import com.mt.course.mapper.ZhiboCourseEntityMapper;

@Component
public class ZhiboCourseServiceModel {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ZhiboCourseServiceModel.class);

    @Autowired
    private ZhiboCourseEntityMapper zhiboCourseEntityMapper;

    public ServiceResult<List<ZhiboCourseEntity>> selectList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        Assert.notNull(this.zhiboCourseEntityMapper, "Property 'zhiboCourseEntityMapper' is required.");
        ServiceResult<List<ZhiboCourseEntity>> result = new ServiceResult<List<ZhiboCourseEntity>>();
        try {
            if (pagerInfo != null) {
                PageHelper.startPage(pagerInfo.getPageIndex(), pagerInfo.getPageSize());
            }

            result.setResult(this.zhiboCourseEntityMapper.selectList(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ZhiboCourseServiceModel][selectList]：query selectList occur exception", e);
        }
        return result;
    }

    public ServiceResult<ZhiboCourseEntity> selectInfo(Map<String, Object> params) {
        Assert.notNull(this.zhiboCourseEntityMapper, "Property 'zhiboCourseEntityMapper' is required.");
        ServiceResult<ZhiboCourseEntity> result = new ServiceResult<ZhiboCourseEntity>();
        try {
            result.setResult(this.zhiboCourseEntityMapper.selectByPrimaryKey(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ZhiboCourseServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> insert(ZhiboCourseEntity zhiboCourseEntity) {
        Assert.notNull(this.zhiboCourseEntityMapper, "Property 'zhiboCourseEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.zhiboCourseEntityMapper.insert(zhiboCourseEntity);
            if (save > 0) {
                id = zhiboCourseEntity.getZhiboCourseId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ZhiboCourseServiceModel][insert]：query insert occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateRelate(ZhiboCourseEntity zhiboCourseEntity) {
        Assert.notNull(this.zhiboCourseEntityMapper, "Property 'zhiboCourseEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.zhiboCourseEntityMapper.updateByPrimaryKeySelective(zhiboCourseEntity);
            if (save > 0) {
                id = zhiboCourseEntity.getZhiboCourseId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ZhiboCourseServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateByPrimaryKeySelective(ZhiboCourseEntity zhiboCourseEntity) {
        Assert.notNull(this.zhiboCourseEntityMapper, "Property 'zhiboCourseEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.zhiboCourseEntityMapper.updateByPrimaryKeySelective(zhiboCourseEntity);
            if (save > 0) {
                id = zhiboCourseEntity.getZhiboCourseId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ZhiboCourseServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> deleteByPrimaryKey(Integer zhiboCourseId) {
        Assert.notNull(this.zhiboCourseEntityMapper, "Property 'zhiboCourseEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int save = 0;
        try {
            save = this.zhiboCourseEntityMapper.deleteByPrimaryKey(zhiboCourseId);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ZhiboCourseServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }
}
